package com.dm.util;

import lombok.Getter;

import java.io.Serializable;

public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = -5316018247813336695L;

    /**
     * 响应码或状态码
     */
    private Integer code;

    /**
     * 信息
     */
    private String msg;

    /**
     * 返回数据
     */
    @Getter
    private T data;

    private ResponseResult(int code) {

        this.code = code;
    }

    private ResponseResult(int code, T data) {
        this.code = code;
        this.data = data;
    }

    private ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getcode() {
        return code;
    }

    public String getMessage() {
        return msg;
    }

    public static <T> ResponseResult<T> error(int code, String error) {
        return new ResponseResult<T>(code, error);
    }

    public static <T> ResponseResult<T> ok(int code, String msg,T data) {
        return new ResponseResult<T>(code, msg,data);
    }

    public static <T> ResponseResult<T> ok(int code, String msg) {
        return new ResponseResult<T>(code, msg);
    }
}